package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import db.ItemStore;

import util.DBUtil;

@WebServlet("/itemQuantity")
public class ItemQuantityController extends BaseController {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doOnPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			SQLException {
		RequestDispatcher view = request.getRequestDispatcher("/searchItemQuantity.jsp");
		if(request.getParameter("name") != null){
			DBUtil dbUtil = new DBUtil();
			String name = request.getParameter("name");
			List<ItemStore> items = dbUtil.getItemCount(name);
			request.setAttribute("items", items);
			request.setAttribute("name", name);
		}
		view.forward(request, response);

	}

	@Override
	protected void doOnGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException,
			SQLException {
		RequestDispatcher view = request.getRequestDispatcher("/searchItemQuantity.jsp");
		view.forward(request, response);

	}

}
